# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import json
from django.http import HttpResponse
from django.shortcuts import render

from ustv.video.series import TV_Series
from ustv.common import Utils

# Create your views here.

def query_series(request):
    if request.method == "GET":
        title = request.GET.get("title", None)
        season = request.GET.get("season", None)
        series = TV_Series()
        status, reason, data = series.queryBySeriesInfo(title, season)
        response = HttpResponse(Utils.genResponse(status, reason, data), content_type="application/json")
        response['Access-Control-Allow-Origin']='*'
        return response

def need_crawl(request):
    if request.method == "GET":
        title = request.GET.get("title", None)
        updatetip = request.GET.get("updatetip", None)
        series = TV_Series()
        status, reason, data = series.needCrawl(title, updatetip)
        response = HttpResponse(Utils.genResponse(status, reason, data), content_type="application/json")
        response['Access-Control-Allow-Origin']='*'
        return response

def take_task(request):
        series = TV_Series()
        status, reason, data = series.takeTask()
        response = HttpResponse(Utils.genResponse(status, reason, data), content_type="application/json")
        response['Access-Control-Allow-Origin'] = '*'
        return response